{*
 * @author 		Zprofess <contact@zprofess.com>
 * @copyright  	2011 Zprofess
 * @version  	1.0 
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 *}

<div id="idTabReviews">

	<script type="text/javascript">
		$(document).ready(function(){ldelim}
		
			// togge
			$('#addReviewBtn').click(function(){ldelim} 
				$('#reviewForm').slideDown('slow');
				$('input#addReviewBtn').slideUp('slow');
			{rdelim}); 
			
			$('#removeReviewForm').click(function(){ldelim}  
				$('#reviewForm').slideUp('fast');
				$('input#addReviewBtn').fadeIn('slow');
			{rdelim});
			
			$('#removeReviewEditForm').click(function(){ldelim}  
				$('#reviewFormEdit').slideUp('fast');
				$('input#addReviewBtn').fadeIn('slow');
			{rdelim});
			
			
		
			// by xuanhoapro::
			$("#popup-vote-success").dialog({ldelim}
					modal: true ,
					width:300,
					height:85,
					show:"clip",
					hide:"clip",
					title: "{l s='Notification'}",
					autoOpen:false
			{rdelim});
			$("#popup-vote-already").dialog({ldelim}
				modal: true ,
				width:300,
				height:85,
				show:"clip",
				hide:"clip",
				title: "{l s='Notification'}",
				autoOpen:false
			{rdelim});
			$("#popup-vote-notLogged").dialog({ldelim}
				modal: true ,
				width:300,
				height:85,
				show:"clip",
				hide:"clip",
				title: "{l s='Notification'}",
				autoOpen:false
			{rdelim});
			//end--
			
			// for add review
			$(".ratingZprofess").each(function(i) {
			  	$(this).raty({
					width: 			{$configRating['width']},
					cancel: 		{$configRating['cancel']},						
					cancelHint:   	"{$configRating['cancelHint']}",  
					cancelOff:  	"{$configRating['cancelOff']}",
					cancelOn:   	"{$configRating['cancelOn']}", 	
					cancelPlace:  	"{$configRating['cancelPlace']}", 
				
					half:  			{$configRating['half']},
					space:       	false, 
					hintList:		{$configRating['hintList']},
					noRatedMsg:		"{$configRating['noRatedMsg']}",
					number:     	{$configRating['number']},
					path:           "{$configRating['path']}",	
					starHalf:		"{$configRating['starHalf']}",
					starOff:		"{$configRating['starOff']}",
					starOn:			"{$configRating['starOn']}",				
					start: 			{$configRating['start']},
				});
				
				$(this).children('input[name="score"]')
		            .attr('name', 'score_' + (i + 1));
			});
		{rdelim});
	</script>
	
	{include file="$tpl_dir./errors.tpl"}
	{if isset($errors) || isset($confirmation) || isset($param_p) || isset($param_n)} 
		<script type="text/javascript">
			$(document).ready(function(){ldelim}
				// change selected tab
				$('#more_info_tab_more_info').removeClass('selected');
				$('#idTabReviewsZprofess').addClass('selected');
				$('#idTabReviews').removeClass('block_hidden_only_for_screen');
				$('#idTab1').addClass('block_hidden_only_for_screen');
			{rdelim});
		</script>
	{/if}
	{if isset($errors)}
		<script type="text/javascript">
			$(document).ready(function(){ldelim}
				$('#reviewForm').slideDown('slow');
				$('input#addReviewBtn').slideUp('slow');
			{rdelim});
		</script>
	{/if}
	
	<!-- display review -->
	{if $reviews|@count gt 0}
		<div class="block_comment">
			<ul class="products clearfix">
				{foreach from=$reviews item=review}
				<li class="thead clearfix" id="li_header_comment_{$review.id_zproduct_review}">
					<!-- by xuanhoapro:: show custommer alias or name -->
					<div class="f-left"><b>{$review.customer_name|escape:'html':'UTF-8'}</b></div>
					<div class="f-right">{$review.date_add}</div>
				</li>
					<li class="item clearfix" id="li_comment_{$review.id_zproduct_review}">
						<div class="info f-left" style="width: 25%">
							{if $review.badges}
					    		<div>{l s="Badges:"} <span class="new">{$review.badges}</span></div> 
					    	{/if}
							{if !{$only_review}}
								{l s="Rating:"} {$review.rating|string_format:"%.1f"}
								<div id="review-avg-raty-{$review.id_zproduct_review}" class="displayRatingZprofess_{$review.id_zproduct_review}"></div>
								<script type="text/javascript">
									// avg each rating review
									$(".displayRatingZprofess_{$review.id_zproduct_review}").raty({									
										width: 			{$configRating['width']},
										cancel: 		{$configRating['cancel']},						
										cancelHint:   	"{$configRating['cancelHint']}",  
										cancelOff:  	"{$configRating['cancelOff']}",
										cancelOn:   	"{$configRating['cancelOn']}", 	
										cancelPlace:  	"{$configRating['cancelPlace']}", 
									
										half:  			true,
										space:       	false,  
										hintList:		{$configRating['hintList']},
										noRatedMsg:		"{$configRating['noRatedMsg']}",
										number:     	{$configRating['number']},
										path:           "{$configRating['path']}",	
										starHalf:		"{$configRating['starHalf']}",
										starOff:		"{$configRating['starOff']}",
										starOn:			"{$configRating['starOn']}",
										readOnly:		true,
										start: 			{$review.rating},
									});
									
									function loadIdReviewEdit(id) {
									
										$('input#addReviewBtn').slideUp('slow');
									
										$("input#id_zproduct_review_edit").val(id);
										var content =$("input#content_review_edit_"+id).val();
										var title =$("input#title_"+id).val();
										$("textarea#content_edit").html(content.replace(/<br \/>/ig,""));
										$("#text_edit").val(title.replace(/<br \/>/ig,""));
										$("#reviewFormEdit").show ();
										$.scrollTo('#reviewFormEdit', 1200 );
										$("#tableEditReview").remove();
										var html ='<table id="tableEditReview" border="0" cellspacing="0" cellpadding="0"><tbody>{section loop=$criterions name=i start=0 step=1}<tr><td><input type="hidden" name="id_zproduct_criterion_{$smarty.section.i.iteration}" value="{$criterions[i].id_zproduct_criterion|intval}" />{$criterions[i].name|escape:'html':'UTF-8'}</td><td><div class="ratingZprofessEdit" id="{$smarty.section.i.iteration}_grade_edit" name="{$smarty.section.i.iteration}_grade_edit"></div></td></tr>{/section}</tbody></table>';
										
										$("h3#heditReview").after(html);
										
										{section loop=$criterions name=i start=0 step=1}
											$("#{$smarty.section.i.iteration}_grade_edit").html('');
											$("#{$smarty.section.i.iteration}_grade_edit").raty({
												width: 			{$configRating['width']},
												cancel: 		{$configRating['cancel']},						
												cancelHint:   	"{$configRating['cancelHint']}",  
												cancelOff:  	"{$configRating['cancelOff']}",
												cancelOn:   	"{$configRating['cancelOn']}", 	
												cancelPlace:  	"{$configRating['cancelPlace']}", 
											
												half:  			{$configRating['half']},
												space:       	false, 
												hintList:		{$configRating['hintList']},
												noRatedMsg:		"{$configRating['noRatedMsg']}",
												number:     	{$configRating['number']},
												path:           "{$configRating['path']}",	
												starHalf:		"{$configRating['starHalf']}",
												starOff:		"{$configRating['starOff']}",
												starOn:			"{$configRating['starOn']}",
												readOnly:		false,
												start: 			$("input#rating_edit_{$smarty.section.i.iteration}_"+id).val(),
											});
										{/section}
										$(".ratingZprofessEdit").each(function(i) {
											$(this).children('input[name="score"]')
									            .attr('name', 'edit_score_' + (i + 1));
										});
									}
									$('#plTabReview').click (function() {
										$("#reviewFormEdit").hidden ();
									});
									
								</script>
							{/if}
							{if $display_email == true}
								{$review.email|escape:'html':'UTF-8'}<br />
							{/if}
							{if $display_website == true}
								{$review.website|escape:'html':'UTF-8'}
							{/if}
                            <div style="margin-bottom: 0px">
                                <a href="{$modules_dir}reviewratingsynthesis/review.php?id_customer={$review.id_customer|escape:'html':'UTF-8'}">{l s='View my all review' mod='reviewratingsynthesis'}</a>
                            </div>
						</div>
						<div class="comment-detail f-left" style="width:70%">
							<div class="f-left" {if $enable_vote == true}style="width:80%"{/if}>
								{if $display_title == true}
									<span><b>{$review.title}</b></span>
								{/if}
								<input type="hidden" name="title_{$review.id_zproduct_review}" id="title_{$review.id_zproduct_review}" value="{$review.title|escape:'html':'UTF-8'|nl2br}">
								{foreach from=$review.ratings key=k item=v}
								    <input type="hidden" name="rating_edit_{$k}_{$review.id_zproduct_review}" id="rating_edit_{$k}_{$review.id_zproduct_review}" value="{$v|escape:'html':'UTF-8'|nl2br}">
								{/foreach}
								
								<div class="content">
									{$review.content|escape:'html':'UTF-8'|nl2br}
									
									{if $review.id_customer ==  $id_customer && $cookie->isLogged() == true}
									<a class="comment_delete" href="#" id="{$review.id_zproduct_review}">
										<img title="Delete" alt="Delete" src="{$modules_dir}../img/admin/delete.gif">
									</a>
									<input type="hidden" name="content_review_edit_{$review.id_zproduct_review}" id="content_review_edit_{$review.id_zproduct_review}" value="{$review.content|escape:'html':'UTF-8'|nl2br}"> 
									<a onclick="loadIdReviewEdit ({$review.id_zproduct_review});" href="#">
										<img border="0" title="Edit" alt="Edit" src="{$modules_dir}../img/admin/edit.gif">
									</a>
									{/if}
								</div>
							</div>
							{if $enable_vote == true}
								<ul class="f-right">
									<li style="margin-bottom: 0px;">
										<span id="number_like_{$review.id_zproduct_review}" class="like f-left">{$review.vlike}</span>
											<a class="comment_like_up" id="link_like_{$review.id_zproduct_review}" href="" title="Like">
												<img width="16" height="16" alt="Like" src="{$modules_dir}reviewratingsynthesis/img/like.png">
											</a> 
									</li>
									<li style="margin-bottom: 0px;">
										<span id="number_dislike_{$review.id_zproduct_review}" class="like f-left">{$review.vdislike}</span>
											<a class="comment_dislike_up" id="link_dislike_{$review.id_zproduct_review}" href="" title="Dislike">
												<img width="16" height="16" alt="Dislike" src="{$modules_dir}reviewratingsynthesis/img/dislike.png">
											</a>
									</li>
								</ul>
							{/if}
						</div>
					</li>
					{if isset($review.reply_employees) and $review.reply_employees!=null}
					<li id="li_comment_admin_{$review.id_zproduct_review}" class="item clearfix">
						<div style="width: 24%" class="info f-left">
							Repply by <span class="username">{$review.name_employees|truncate:20}</span>
						</div>
						<div style="width:74%" class="comment-detail f-left">
	                        {$review.reply_employees|escape:'html':'UTF-8'|nl2br}
						</div>
					</li>
					{/if}
				{/foreach}
			</ul>
		</div>
	{else}
		<p class="align_center">{l s='No customer reviews for the moment.' mod='reviewratingsynthesis'}</p>
	{/if}
	
	<form action="" method="post" id="reviewFormEdit" class="std" style="display:none;">
		<fieldset>
			<h3 id="heditReview">{l s='Edit your rating for the product' mod='reviewratingsynthesis'}
			    <span style="float:right;"><a id="removeReviewEditForm" href="javaScript:void(0);">X</a></span>
			</h3>
			
		</fieldset>
		<fieldset>
			<input type="hidden" id="id_zproduct_review_edit" name="id_zproduct_review_edit" value="">
			<h3>Edit your review</h3>
			<p class="required text">
				<label for="title">Title </label>
				<input type="text" id="text_edit" size="43" name="text_edit" value="">
			</p>
			<p class="required textarea">
				<label for="content">Your review</label>
				<textarea name="content_edit" id="content_edit" rows="4" cols="41">{if isset($smarty.post.content)}{$smarty.post.content|escape:'htmlall':'UTF-8'|stripslashes}{/if}</textarea>
			</p>
			<input type="submit" id="editComment" name="submitReviewEdit" value="Edit"style="margin-left: 452px; margin-top: 4px;">
		</fieldset>
	</form>
	
	<!-- add review -->
	{if $too_early == true}
		<p class="align_center">{l s='You should wait' mod='reviewratingsynthesis'} {$delay} {l s='second(s) before posting a new review' mod='reviewratingsynthesis'}</p>
	{elseif $cookie->isLogged() == true || $allow_guests == true}
		<p class="align_center" style="width:100%;">
			<input style="margin:auto;" class="exclusive" type="button" id="addReviewBtn" value="{l s='Add a reviews' mod='reviewratingsynthesis'}"/>
		</p>
		<form action="" method="post" id="reviewForm" class="std" style="display:none;">
			{if $criterions|@count gt 0 AND !{$only_review}}	
				<fieldset>
					<h3>{l s='Your rating for the product' mod='reviewratingsynthesis'}
					    <span style="float:right;"><a id="removeReviewForm" href="javaScript:void(0);">X</a></span>
					</h3>
					<table border="0" cellspacing="0" cellpadding="0"><tbody>
						{section loop=$criterions name=i start=0 step=1}
							<tr>
								<td>
									<input type="hidden" name="id_zproduct_criterion_{$smarty.section.i.iteration}" 
										   value="{$criterions[i].id_zproduct_criterion|intval}" />
									{$criterions[i].name|escape:'html':'UTF-8'}
								</td>
								<td>
									<div class="ratingZprofess" id="{$smarty.section.i.iteration}_grade"
														name="{$smarty.section.i.iteration}_grade"></div>
								</td>
							</tr>
						{/section}
					</tbody></table>
				</fieldset>
			{/if}
			
			<fieldset>
				<h3>{l s='Your review' mod='reviewratingsynthesis'}</h3>
				{if $cookie->isLogged() == false}
					<p class="required text">
						<label for="customer_name">{l s='Your name' mod='reviewratingsynthesis'} </label>
						<input type="text" class="text" name="customer_name" id="customer_name"
						value="{if isset($smarty.post.customer_name)}{$smarty.post.customer_name|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
						<sup>*</sup>
					</p>
					{if $enable_email == true}
						<p class="text">
							<label for="email">{l s='Email' mod='reviewratingsynthesis'} </label>
							<input type="text" class="text" name="email" id="email"
							value="{if isset($smarty.post.email)}{$smarty.post.email|escape:'htmlall':'UTF-8'|stripslashes}{/if}"
							/>
						</p>
					{/if}
				{/if}
				{if $enable_website == true}
					<p class="text">
						<label for="website">{l s='Website' mod='reviewratingsynthesis'} </label>
						<input type="text" class="text" name="website" id="website"
						value="{if isset($smarty.post.website)}{$smarty.post.website|escape:'htmlall':'UTF-8'|stripslashes}{/if}"
						/>
					</p>
				{/if}
				<p class="required text">
					<label for="title">{l s='Title' mod='reviewratingsynthesis'} </label>
					<input type="text" class="text" name="title" id="title" size="43"
					value="{if isset($smarty.post.title)}{$smarty.post.title|escape:'htmlall':'UTF-8'|stripslashes}{/if}"
					/>
					<sup>*</sup>
				</p>
				<p class="required textarea">
					<label for="content">{l s='Your review' mod='reviewratingsynthesis'}</label>
					<textarea name="content" id="content" cols="41" rows="4">{if isset($smarty.post.content)}{$smarty.post.content|escape:'htmlall':'UTF-8'|stripslashes}{/if}</textarea>
					<sup>*</sup>
				</p>
				{if $enable_captcha == true}
					<p class="required text">
						<label for="security check">{l s='Security Check' mod='reviewratingsynthesis'} </label>
						<img id="siimage" class="img_captcha" src="{$module_dir}lib/securimage/zprofess_securimage_show.php" alt="CAPTCHA Image" align="left">
						<object type="application/x-shockwave-flash" data="{$module_dir}lib/securimage/securimage_play.swf?audio_file={$module_dir}lib/securimage/securimage_play.php&amp;bgColor1=#fff&amp;bgColor2=#fff&amp;iconColor=#777&amp;borderWidth=1&amp;borderColor=#000" height="32" width="32">
							<param name="movie" value="{$module_dir}lib/securimage/securimage_play.swf?audio_file={$module_dir}lib/securimage/securimage_play.php&amp;bgColor1=#fff&amp;bgColor2=#fff&amp;iconColor=#777&amp;borderWidth=1&amp;borderColor=#000">
						</object>
						&nbsp;
						<a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = '{$module_dir}lib/securimage/zprofess_securimage_show.php?sid=' + Math.random(); this.blur(); return false"><img src="{$module_dir}lib/securimage/images/refresh.png" alt="Reload Image" onclick="this.blur()" align="bottom" border="0"></a><br />
						<input type="text" class="input_captcha" name="captcha" size="14" maxlength="14" />
						<sup>*</sup>
					</p>
				{/if}
			</fieldset>
			<p class="cart_navigation required">
				<input type="submit" name="submitReview" id="submitReview" value="{l s='Submit Review' mod='reviewratingsynthesis'}" class="exclusive" />
				<span><sup>*</sup>{l s='Your review will appear in the name of' mod='reviewratingsynthesis'}
								  {$customer_name} .
								  {l s='You can change this on the My Personal Information page.' mod='reviewratingsynthesis'}
				</span>
			</p>
		</form>
	{else}
		<p class="align_center">
			{l s='Only registered users can post a new comment & vote.' mod='reviewratingsynthesis'} <br />
			{l s='Please click '}<a href="{$link->getPageLink('authentication.php', true)}?back=product.php?id_product={$product->id|intval}">{l s='here'}</a> {l s='to login or register.'}
		</p>
	{/if}
	{include file="$pagination_dir"}
</div>
<!-- by xuanhoapro :: popup vote notification -->
<div id="vote-popup" class="vote-popup" style="display:none;">
	<div id="popup-vote-success">{l s='Vote has been added.'}</div>
	<div id="popup-vote-already">{l s='You was voted already.'}</div>
	<div id="popup-vote-notLogged">{l s='You must '}<a href="{$link->getPageLink('authentication.php', true)}?back=product.php?id_product={$product->id|intval}">{l s='login'}</a> {l s=' to vote.'}</div>
</div>